package com.steven.ourcontest.collect.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.bumptech.glide.request.RequestOptions
import com.steven.ourcontest.R
import com.steven.ourcontest.app.AppRouter
import com.steven.ourcontest.chat.bean.Friend
import com.steven.ourcontest.collect.bean.TeamCollection
import com.steven.ourcontest.contest.bean.MatchCollection
import com.steven.ourcontest.forum.bean.DiscussBean
import com.steven.ourcontest.me.widget.GlideRoundTransform
import com.steven.ourcontest.net.NetConstants
import com.steven.ourcontest.utils.DateUtil

class MatchCollectionListAdapter(private val context: Context, private val itemClickListener: ((teamId: Long) -> Unit)) :
    RecyclerView.Adapter<MatchViewHolder>() {
    val listData by lazy {
        ArrayList<MatchCollection>()
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MatchViewHolder {
        val inflater =
            LayoutInflater.from(context).inflate(R.layout.item_match_collection, parent, false)
        return MatchViewHolder(inflater)
    }

    override fun getItemCount(): Int {
        return listData.size
    }

    override fun onBindViewHolder(holder: MatchViewHolder, position: Int) {
        val itemData = listData[position]
        holder.apply {
            tv_match_name?.text = itemData.name
            itemData.belong?.let {
                tv_belong?.text = "主办方：${it}"
            }
            tv_signup_time?.text = "报名时间：${if (itemData.signUpStartTime != 0L && itemData.signUpEndTime != 0L) {
                DateUtil.timeStamp2Date(
                    itemData.signUpStartTime?.times(1000),
                    "yyyy.MM.dd"
                ) + "~" + DateUtil.timeStamp2Date(itemData.signUpEndTime?.times(1000), "yyyy.MM.dd")
            } else {
                "暂无"
            }}"
            tv_match_time?.text = "比赛时间：${if (itemData.matchStartTime != 0L && itemData.matchEndTime != 0L) {
                DateUtil.timeStamp2Date(
                    itemData.matchStartTime?.times(1000),
                    "yyyy.MM.dd"
                ) + "~" + DateUtil.timeStamp2Date(itemData.matchEndTime?.times(1000), "yyyy.MM.dd")
            } else {
                "暂无"
            }}"
            itemView.setOnClickListener {
                AppRouter.openMatchDetailActivity(context, itemData.id)
            }
        }
    }
}

class MatchViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
    val tv_match_name: TextView? = itemView.findViewById(R.id.tv_match_name)
    val tv_belong: TextView? = itemView.findViewById(R.id.tv_belong)
    val tv_signup_time: TextView? = itemView.findViewById(R.id.tv_signup_time)
    val tv_match_time: TextView? = itemView.findViewById(R.id.tv_match_time)
}
